#include<stdio.h>

void Selectsort(int r[],int n)
{
	int i,j,index,temp;
	for(i=0;i<n;i++)
	{
		index=i;
		for(j=i+1;j<n;j++)
		{
			if(r[j]<r[index])
				index=j;
		}
		if(index!=j)
		{
			temp=r[i];
			r[i]=r[index];
			r[index]=temp;
		}
		printf("%d ",r[i]);
	}
}

void BubbleSort(int r[],int n)
{
	int bound,exchange=n-1;
	int i,j,temp;
	while(exchange!=0)
	{
		bound=exchange;
		exchange=0;
		for(j=0;j<bound;j++)
		{
			if(r[j]>r[j+1])
			{
				temp=r[j];
				r[j]=r[j+1];
				r[j+1]=temp;
				exchange=j;
			}
		}
	}
	for(i=0;i<n;i++)
	{
		printf("%d ",r[i]);
	}
}
int main()
{
	int r[]={8 ,3 ,6 ,2 ,7 ,1 ,5 ,4};
	int n=8;
//	Selectsort(r,n);
	BubbleSort(r,n);
	return 0;
}
